<?php
class FileAction extends BaseAction
{
    public function do_upload()
    {
        $this->require_login();
        if (intval($_REQUEST['upload_type']) == 0)
            $result = $this->uploadFile();
        else
            $result = $this->uploadImage();
        if ($result['status'] == 1) {
            $list = $result['data'];
            if (intval($_REQUEST['upload_type']) == 0){
                $file_url = $list[0]['recpath'] . $list[0]['savename'];
            }
            else {
                $file_url = $list[0]['bigrecpath'] . $list[0]['savename'];
            }
            header('Content-type: text/html; charset=UTF-8');
            echo json_encode(array('error' => 0, 'url' => $file_url),JSON_HEX_TAG);
            exit();
        } else {
            $this->alert($result['info']);
        }
    }

    public function do_upload_img()
    {
        //$this->require_login();
        if (intval($_REQUEST['upload_type']) == 0) {
            $result = $this->uploadFile();
        } else {
            $result = $this->uploadImage();
        }
        if ($result['status'] == 1) {
            $list = $result['data'];
            if (intval($_REQUEST['upload_type']) == 0) {
                $file_url = $list[0]['recpath'] . $list[0]['savename'];
            } else {
                $file_url = $list[0]['bigrecpath'] . $list[0]['savename'];
            }
            header('Content-type: text/html; charset=UTF-8');
            echo json_encode(array('error' => 0, 'url' => $file_url),JSON_HEX_TAG);
            exit();
        } else {
            $this->alert($result['info']);
        }
    }

    function alert($msg) {
        header('Content-type: text/html; charset=UTF-8');
        echo json_encode(array('error' => 1, 'message' => $msg),JSON_HEX_TAG);
        exit;
    }

}
?>